package com.dhl.fin.api.domain;

import com.dhl.fin.api.common.annotation.BusinessId;
import com.dhl.fin.api.common.domain.BasicDomain;
import com.dhl.fin.api.common.util.DateUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.sql.Timestamp;

/**
 * @author CuiJianbo
 * @since 2025/3/15
 */

/**
 * 登录账号
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "t_login_account")
public class LoginAccount extends BasicDomain {

    @BusinessId
    @Column(columnDefinition = "varchar(50)")
    private String wxAccountCode;

    @Column(columnDefinition = "varchar(50)")
    private String sessionKey;

    @Column(columnDefinition = "datetime")
    private Timestamp loginTime;

    @Transient
    private String loginTimeStr;

    public static LoginAccount getInstance(String openId, String sessionKey) {
        LoginAccount loginAccount = new LoginAccount();
        loginAccount.setWxAccountCode(openId);
        loginAccount.setSessionKey(sessionKey);
        loginAccount.setLoginTime(DateUtil.getSysTime());
        return loginAccount;
    }

    public LoginAccount getUpdateInstance(String sessionKey) {
        setSessionKey(sessionKey);
        setLoginTime(DateUtil.getSysTime());
        return this;
    }

}
